<script setup lang="ts">
import { useChartAutoResize } from '@/mixins/MixinChartAutoResize'
import type { VChartInstance } from '@/types'
import VueEcharts from 'vue-echarts'

const props = defineProps<{
  data: { categoryName: string, total: number | string, [key: string]: any }[]
}>()

const designStore = useDesignStore()
const option = computed(() => {
  // echarts 饼图option
  return {
    tooltip: {
      trigger: 'item',
    },
    series: [
      {
        name: '各类别温室气体排放量及占比',
        type: 'pie',
        radius: ['36%', '60%'],
        center: ['50%', '50%'],
        data: props.data.map(v => ({
          name: v.categoryName,
          value: v.total,
        })),
      },
    ],
  }
})

const chartRef = ref<VChartInstance>()

useChartAutoResize(chartRef)
</script>

<template>
  <VueEcharts
    ref="chartRef"
    :option="option" :init-options="{
      locale: 'zh',
    }" :theme="designStore.theme"
  />
</template>
